import tensorflow as tf

# y = w * x
w = tf.constant(1.)
x = tf.constant(5.)

y = x * w
with tf.GradientTape(persistent=True) as tape:
    tape.watch([w])
    loss = x * w

'''with tf.GradientTape() as tape:
    tape.watch([w])
    loss = x * w'''

grad = tape.gradient(loss, [w])
grad = tape.gradient(loss, [w])

print(grad)
print(w.numpy())

